import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Observable;

public class DictionaryClientResponseReceiver extends Observable implements
		Runnable {
	private ObjectInputStream inStream;
	private boolean stopped;

	public DictionaryClientResponseReceiver(ObjectInputStream stream) {
		inStream = stream;

		stopped = false;
	}

	@Override
	public void run() {
		while (!stopped && inStream != null) {
			try {
				Message response = (Message) inStream.readObject();
				setChanged();
				notifyObservers(response);
			} catch (ClassNotFoundException | IOException e) {
				stopped = true;
			}
		}
	}

	public void setStop() {
		stopped = true;
	}
}
